var city = '沧州';
function loadXMLDoc() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var json = xmlhttp.responseText;
            //把返回的数据，转换成数组对象格式
            json = JSON.parse(json);
            console.log(json);
            //城市
            document.querySelector("#city").innerHTML = json.basic.city;
            //天气
            document.querySelector("#now").innerHTML = json.now.cond.txt;
            //风向
            document.querySelector("#wind").innerHTML = json.now.wind.dir;
            //度数
            document.querySelector("#tmp").innerHTML = json.now.tmp;
            //风级
            document.querySelector("#ji").innerHTML = json.now.wind.sc;
            //穿衣指数
            document.querySelector("#brf").innerHTML = json.suggestion.drsg.brf;
            document.querySelector("#drsg").innerHTML = json.suggestion.drsg.txt;
            //洗车指数
            document.querySelector("#br").innerHTML = json.suggestion.cw.brf;
            document.querySelector("#txt").innerHTML = json.suggestion.cw.txt;
            //空气
            document.querySelector("#air").innerHTML = json.suggestion.air.brf;
            document.querySelector("#tlt").innerHTML = json.suggestion.air.txt;
            //紫外线
            document.querySelector("#uv").innerHTML = json.suggestion.uv.brf;
            document.querySelector("#tdt").innerHTML = json.suggestion.uv.txt;
            //运动
            document.querySelector("#sport").innerHTML = json.suggestion.sport.brf;
            document.querySelector("#spo").innerHTML = json.suggestion.sport.txt;
            //感冒指数
            document.querySelector("#flu").innerHTML = json.suggestion.flu.brf;
            document.querySelector("#fl").innerHTML = json.suggestion.flu.txt;
            //时段
            for (var a=0 ;a<7;a++){
                document.querySelectorAll(".p1")[a].innerHTML = json.hourly_forecast[a].date;
            }
            for (var c=0;c<7;c++){
                document.querySelectorAll(".p2")[c].innerHTML = json.hourly_forecast[c].tmp+"°";
            }
            for (var b=0;b<7;b++){
                document.querySelectorAll(".p3")[b].innerHTML = json.hourly_forecast[b].wind.dir;
            }

            //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city=" + city,true);
    xmlhttp.send();
}

loadXMLDoc();
document.querySelector("#ipt").addEventListener('change',function () {
    console.log(this.value);
    //赋值城市
    city = this.value;
    //执行要查询天气的方法
    loadXMLDoc();
});